package com.smarkparking.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.smarkparking.dao.UserproposalDao;
import com.smarkparking.pojo.User;
import com.smarkparking.pojo.Userproposal;
import com.smarkparking.service.UserService;
import com.smarkparking.service.UserproposalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 刘涛
 * @create 2021/11/21 18:30
 */
@Service
public class UserproposalServiceImpl implements UserproposalService {
    @Autowired
    private UserproposalDao userproposalDao;
    @Autowired
    private UserService userService;

    @Override
    public List<Userproposal> findProposalByEmail(String email) {
        QueryWrapper<Userproposal> qwp = new QueryWrapper<>();
        qwp.eq("email", email);
        List<Userproposal> userproposals = userproposalDao.selectList(qwp);
        return userproposals;
    }

    @Override
    public List<Userproposal> findProposalAll() {
        List<Userproposal> userproposals = userproposalDao.selectList(null);
        return userproposals;
    }

    @Override
    public void addProposal(String email, String proposal) {
        User user = userService.selectUserByEmail(email);
        Userproposal userproposal = new Userproposal();
        userproposal.setEmail(email);
        userproposal.setProposal(proposal);
        userproposal.setName(user.getName());
        userproposalDao.insert(userproposal);
    }

    @Override
    public void readProposal(Integer id) {
        Userproposal userproposal = new Userproposal();
        userproposal.setProposalState(1);
        userproposal.setId(id);
        userproposalDao.updateById(userproposal);
    }
}
